package com.atgion.manager.controller;

import com.atgion.manager.service.SysUserService;
import com.atgion.common.log.annoyation.Log;
import com.atgion.spzx.model.dto.system.SysUserLoginParam;
import com.atgion.spzx.model.entity.system.ValidateCodeVo;
import com.atgion.spzx.model.vo.base.Result;
import com.atgion.spzx.model.vo.system.LoginResult;
import com.atgion.spzx.model.vo.system.UserInfoVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequiredArgsConstructor
@Tag(name = "SysUserLoginController")
@RequestMapping("/auth")
public class SysUserLoginController {

    private final SysUserService sysUserService;

    @Operation(summary = "登录")
    @PostMapping(value = "/login")
    public Result<LoginResult> login(@RequestBody SysUserLoginParam sysUserLoginParam) {
        return Result.success(sysUserService.login(sysUserLoginParam));
    }

    //    生成图片验证码
    @GetMapping("/generateValidateCode")
    public Result<ValidateCodeVo> generateValidateCode() {
        ValidateCodeVo validateCodeVo = sysUserService.generateValidateCode();
        return Result.success(validateCodeVo) ;
    }

//    重置密码
    @Log(title = "重置密码", businessType = 2)
    @Operation(summary = "重置密码")
    @GetMapping(value = "/resetPassword")
    public Result<Boolean> resetPassword(String password, Long userId) {
        return Result.success(sysUserService.resetPassword(password,userId));
    }

    @Operation(summary = "获取用户信息")
    @GetMapping(value = "/getUserInfo")
    public Result<UserInfoVO> getUserInfo(@RequestHeader("Authorization") String authorizationHeader) {
        return sysUserService.getUserInfo(authorizationHeader);
    }

//    用户退出
    @GetMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String authorizationHeader){
        sysUserService.logout(authorizationHeader);
        return Result.success("退出成功");
    }

}
